package cn.com.dhcc.turbo.web.controller.sysmgr;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.dhcc.app.core.base.BaseController;
import cn.com.dhcc.app.core.handler.pagerhandler.Pager;
import cn.com.dhcc.app.core.handler.pagerhandler.PagerData;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.annotation.TurboMenu;
import cn.com.dhcc.app.pub.core.annotation.TurboMenu.LEAF_MENU;
import cn.com.dhcc.turbo.entity.sysmgr.taskmont.QuartzTriggerVO;
import cn.com.dhcc.turbo.service.sysmgr.TaskMonitorService;

/**
 * <b>定时任务监控Controller</b>
 * 
 * @author Macky_He
 * @version [数据交换平台V1.2.1]
 * @see {@link #taskMonitorService 定时任务监控Service}
 * @see {@link #taskList(Model, Pager, String, String) 获取定时任务列表}
 */
@Controller
@RequestMapping("taskmont")
@TurboMenu(belongToMenu = LEAF_MENU.TASK_MONT)
public class TaskMonitorController extends BaseController {
	private static final String[] QUARTZ_STATES = { "WAITING", "ACQUIRED",
			"EXECUTING", "BLOCKED", "COMPLETE", "PAUSED", "PAUSED_BLOCKED",
			"ERROR" };

	private Logger logger = Log.getLogger(LOGTYPE.TURBO);

	@Autowired
	private TaskMonitorService taskMonitorService;

	/**
	 * <b>获取定时任务列表</b>
	 * 
	 * @param model
	 *            {@link Model}
	 * @param pager
	 *            分页
	 * @param jobName
	 *            页面参数 “任务名称”
	 * @param status
	 *            页面参数 “任务状态”
	 * @return 定时任务监控页面
	 */
	@RequestMapping(value = "/task_list.do")
	public String taskList(Model model, Pager pager, String jobName,
			String status) {
		logger.info("进入方法taskmont/task_list.do");
		PagerData<QuartzTriggerVO> vo = taskMonitorService.getJobList(jobName,
				status, pager);
		if (null == vo) {
			return "taskmont/task_list";
		}
		model.addAttribute("jobList", vo.getDatas());
		model.addAttribute("quartz_state", QUARTZ_STATES);
		setTotoal(model, vo.getTotal());
		logger.info("执行结束taskmont/task_list.do");
		return "taskmont/task_list";
	}
}
